<script runat="server">
  var nav_root = request.data("_nav_root");
  var linkurl = request.data("_linkurl");

  if (!(nav_root === undefined) && !(nav_root.Navs === null)) {
    var breadcrumb = bootstrap_html(nav_root.Subs, ("/" + linkurl.toLowerCase()), 1);
    //var menu = '<div class="leftmenu">' + breadcrumb + '</div>'
    //console.log(menu);
    response.write('<div class="leftmenu">' + breadcrumb + '</div>')
  }

  function bootstrap_html(navs, path, level) {
    if (navs === undefined || navs === null || navs.length == 0) {
      return "";
    }

    var h = '<ul>';

    for (var i = 0; i < navs.length; i++) {
      var nav = navs[i];
      var s_h = bootstrap_html(nav.Subs, path, level + 1);

      var href = "";
      if (nav.LinkUrl != "") {
        if (!(nav.LinkUrl.substring(0, 7) == "http://" || nav.LinkUrl.substring(0, 8) == "https://")) {
          href = "/" + nav.LinkUrl + "/";
        } else {
          href = nav.LinkUrl;
        }
      } else {
        href = "/account/" + nav.ListUrl;
      }

      if (s_h == "") {
        var active = (path == href.toLowerCase()) ? true : false;
        h += '   <li' + (active ? ' class="active"' : '') + '>';
        if (active) {
          h += '       <a href="javascript:void(0);">' + nav.Name + '</a>';
        } else {
          h += '       <a href="' + href + '"' + (nav.Blank ? ' target="_blank"' : '') + '>' + nav.Name + '</a>';
        }
        h += '   </li>';
      } else {
        var active = s_h.indexOf("active") > 0 ? true : false;
        h += '   <li' + (active ? ' class="active"' : '') + '>';
        h += '      <a href="' + href + '"' + (nav.Blank ? ' target="_blank"' : '') + '>' + nav.Name + '</a>';
        h += s_h;
        h += '   </li>';
      }
    }
    h += "</ul>"

    return h
  }
</script>